package com.cip.master.dao.impl;

import java.util.List;

import org.springframework.dao.DataAccessException;

import com.cip.admin.dao.impl.CipHibernateDAOSupport;
import com.cip.master.dao.SectionDAO;
import com.cip.master.model.Section;

public class SectionDAOImpl extends CipHibernateDAOSupport implements
		SectionDAO {

	public Section saveOrUpdate(Section section) {
		getHibernateTemplate().saveOrUpdate(section);
		return section;
	}

	public List<Section> getAllSection() throws Exception {
		return getCipHibernateTemplate().loadAll(Section.class);	
	}

	public Section getSection(int id) throws DataAccessException, Exception {
		return getCipHibernateTemplate().get(Section.class, id);
	}
	
	public List<Section> getAllSectionByClassYear(int id) throws Exception{
		String queryString="select section from Section as section where section.classYear.id="+id;
		return getCipHibernateTemplate().find(queryString);
	}
	
	public Section getSectionByName(String name) throws Exception {
		String query="select section from Section as section where section.sectionName='"+name+"'";
		return (Section)getCipHibernateTemplate().find(query).get(0);
	}

}
